package com.bood.shimmer.modules.demo.service.impl;

import com.bood.shimmer.common.annotation.DataSource;
import com.bood.shimmer.common.enums.DataSourceType;
import com.bood.shimmer.modules.demo.model.Users;
import com.bood.shimmer.modules.demo.mapper.UsersMapper;
import com.bood.shimmer.modules.demo.service.UsersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 用户 服务实现类
 * </p>
 *
 * @author bood
 * @since 2020-11-30
 */
@Service
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements UsersService {

    @Resource
    private UsersMapper usersMapper;


    @Override
    public boolean updateMaster(Users users) {
        int res = usersMapper.updateById(users);
        if (res > 0) {
            return true;
        }
        return false;
    }

    @DataSource(value = DataSourceType.slave1)
    @Override
    public boolean updateSalve1(Users users) {
        int res = usersMapper.updateById(users);
        if (res > 0) {
            return true;
        }
        return false;
    }

    @DataSource(value = DataSourceType.slave2)
    @Override
    public boolean updateSalve2(Users users) {
        System.out.println(1 / 0);

        int res = usersMapper.updateById(users);
        if (res > 0) {
            return true;
        }
        return false;
    }

}
